<template>
  <el-button type="primary" @click="handleButton">节流</el-button>
</template>

<script setup>
// 节流，指定时间内函数只执行一次，若在指定时间内重复触发，只有一次生效
// 限制执行频率，每隔一定时间执行一次。
const throttle = (fn, wait) => {
  let lastTime = 0
  return () => {
    let now = Date.now()
    if (now - lastTime > wait){
      fn()
      lastTime = now
    }
  }
}
const handleButton = throttle(() => {
  console.log('节流点击handleButton')
}, 1000)
</script>

<style lang="scss" scoped></style>